//
//  DetailTrialViewController.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/10.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "DetailTrialViewController.h"
#import "CommonMacro.h"
#import "DetailFreeModel.h"
#import "DetailFreeTrailView.h"
#import "ApplayAdditionVC.h"
@interface DetailTrialViewController ()
{
    DetailFreeTrailView *detailFreeTrial;
    UIScrollView *tssView;
}

@property (nonatomic,strong) NSArray *faluseArray;
@end

@implementation DetailTrialViewController

#pragma  mark 延迟实例化
- (NSMutableArray *)contentArr
{
    if (_contentArr==nil) {
        _contentArr = [[NSMutableArray alloc] init];
    }
    return _contentArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColorWithRGBA(238, 238, 238, 1);
    self.title = @"免费试用";
    
    //数据源  假
    self.faluseArray = [[NSArray alloc] init];
    self.faluseArray = @[@{@"adImageURL":@"http://www.mmisy.com/data/upload/shop/editor/web-101-102-1-1.jpg?458",@"imageURL":@"http://www.mmisy.com/data/upload/shop/editor/web-101-102-1-2.jpg?356",@"title":@"原产美国雅培精装婴幼儿粉",@"timeStart":@"2015/05/10",@"timeStop":@"2015/05/15",@"specification":@"900克",@"useAge":@"1-3岁",@"price":@"395",@"amount":@"50份",@"applied":@"42人",@"estimate":@"025538",@"description":@"haodg asdgr ksfgj sdkghegrf  dghierg dsfgj dsg fgj agh argoh aghe.aghr agher asdfh gdfgh asihf aweph lgh aogih aoerifh sighroigt sedijgte sdlfkg sdkgjl ;psdfijg"}];
    DetailFreeModel *detailFreeModel = [[DetailFreeModel alloc] init];
    [detailFreeModel decodedic:self.faluseArray[0]];
    [self.contentArr addObject:detailFreeModel];
    
    //添加头部View
    [self addTopSubViews];
    //添加参与方式视图
    [self addScrollView];
    //添加底部按钮
    [self applyTrialAndLookDetail];
}

#pragma mark 添加头部的所有内容
- (void)addTopSubViews
{
    detailFreeTrial = [[DetailFreeTrailView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,SCREEN_HEIGHT*0.71)];
    DetailFreeModel *model = self.contentArr[0];
    
    detailFreeTrial.detailFreeModel = model;
//    detailFreeTrial.backgroundColor = [UIColor blueColor];
    [self.view addSubview:detailFreeTrial];
}



#pragma mark 添加 scrollView
- (void)addScrollView
{
    
#warning 这里的参与方式 直接写成图片

    
//    1.计算字的高度
    UILabel *introduceLable = [[UILabel alloc]initWithFrame:CGRectMake(10, 30, SCREEN_WIDTH-20, 60)];
    introduceLable.numberOfLines = 0;
    introduceLable.font = [UIFont fontWithName:@"Helvetica" size:13];
    DetailFreeModel *model = self.contentArr[0];
    NSString *text = model.descriptionM;
    
    UIFont *font = [UIFont fontWithName:@"Helvetica" size:13.0];
    CGSize size = [text sizeWithFont:font constrainedToSize:CGSizeMake(SCREEN_WIDTH-20, 2000.0f)
                       lineBreakMode:NSLineBreakByWordWrapping];
    CGRect rect = introduceLable.frame;
    rect.size = size;
    float viewHeight = size.height;
    [introduceLable setFrame:rect];
    [introduceLable setText:text];
    
    //2.设置scrollView尺寸
    tssView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,detailFreeTrial.frame.size.height+detailFreeTrial.frame.origin.y+2 , SCREEN_WIDTH, SCREEN_HEIGHT*0.21)];
    tssView.contentSize = CGSizeMake(SCREEN_WIDTH, viewHeight);
    tssView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:tssView];
    [tssView addSubview:introduceLable];
    
    UIImageView *smalImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 3, tssView.frame.size.width*0.25, 30)];
    smalImageView.image = [UIImage imageNamed:@"参与方式-侧横幅@2x"];
    [tssView addSubview:smalImageView];
    
    //添加那个小图片
    UILabel *methodLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 3,tssView.frame.size.width*0.25, 30)];
    methodLabel.text = @"参与方式";
    methodLabel.textColor = UIColorWithRGBA(251, 231, 236, 1);
    [tssView addSubview:methodLabel];
}

#pragma mark 添加 申请试用 查看详情 两个button
- (void)applyTrialAndLookDetail
{
    UIButton *applyTrialButton = [[UIButton alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-40, SCREEN_WIDTH*0.495, 40)];
    [applyTrialButton setBackgroundColor:UIColorWithRGBA(232, 65, 109, 1)];
    [applyTrialButton setTitle:@"申请试用" forState:UIControlStateNormal];
    [self.view addSubview:applyTrialButton];
    [applyTrialButton addTarget:self action:@selector(intoApplayAddition) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *lookDetailButton = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH*0.503, SCREEN_HEIGHT-40, SCREEN_WIDTH*0.495, 40)];
    [lookDetailButton setBackgroundColor:UIColorWithRGBA(232, 65, 109, 1)];
    [lookDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
    [self.view addSubview:lookDetailButton];
    
}

#warning  我认为这里 点击的适合要上传请求到服务器
#pragma mark 申请试用跳转到相应界面
- (void)intoApplayAddition
{
    ApplayAdditionVC *appalyAddition = [[ApplayAdditionVC alloc] init];

    [self presentViewController:appalyAddition animated:YES completion:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
